const {ccclass, property} = cc._decorator;

@ccclass
export default class Setting extends cc.Component {
    
    private layers:cc.Node[] = [];
    private bgmSp:cc.Sprite = null
    private soundSp:cc.Sprite = null

    @property(cc.SpriteAtlas)
    uiSpriteAtlas:cc.SpriteAtlas = null

    private isOpenBgm = true
    private isOpenSound = true

    onLoad(){
        this.layers = this.node.getChildByName("layersNode").children
        this.bgmSp = this.layers[0].getChildByName("bgmusicBtn").getComponent(cc.Sprite)
        this.soundSp = this.layers[0].getChildByName("soundfxBtn").getComponent(cc.Sprite)
    }
    start () {

    }

    update (dt) {
        
    }

    onBackHomeClick(){
        cc.director.loadScene("startScene")
    }

    onToggleClick(event, data){
        for(let i = 0; i < 3; i++){
            if(i == data){
                this.layers[i].active = true;
            }else{
                this.layers[i].active = false;
            }
        }
    }

    onBgmBtnClick(){
        if(this.isOpenBgm){
            this.bgmSp.spriteFrame = this.uiSpriteAtlas.getSpriteFrame("soundfx_off_CN")
            this.isOpenBgm = false
        }else{
            this.bgmSp.spriteFrame = this.uiSpriteAtlas.getSpriteFrame("soundfx_on_CN")
            this.isOpenBgm = true
        }
    }

    onSoundBtnClick(){
        if(this.isOpenSound){
            this.soundSp.spriteFrame = this.uiSpriteAtlas.getSpriteFrame("soundfx_off_CN")
            this.isOpenSound = false
        }else{
            this.soundSp.spriteFrame = this.uiSpriteAtlas.getSpriteFrame("soundfx_on_CN")
            this.isOpenSound = true
        }
    }
}
